package com.PVZ.view;

import com.PVZ.view.canvas.BackGroundCanvas;
import com.PVZ.view.canvas.EntityCanvas;
import com.PVZ.view.canvas.ToolsCanvas;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Created by @Author: kabuda on @Date: 2021/5/17 21:21
 * 封装窗口类
 */
@Getter
@Setter
public class GameFrame extends JFrame {

    public static final int WIDTH = 960;
    public static final int HEIGHT = 640;
    private EntityCanvas entityCanvas;
    private BackGroundCanvas backGroundCanvas;
    private ToolsCanvas toolsCanvas;

    public GameFrame(EntityCanvas entityCanvas, BackGroundCanvas backGroundCanvas){
        this.backGroundCanvas = backGroundCanvas;
        this.entityCanvas = entityCanvas;
        this.toolsCanvas = new ToolsCanvas();
        this.setTitle("植物大战僵尸");
        this.setSize(WIDTH,HEIGHT);
        this.add(entityCanvas);
        this.add(toolsCanvas);

        //不可调整窗口大小
        this.setResizable(false);
        //设置位置相对左上角居中
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        this.add(backGroundCanvas);
        this.setVisible(true);
        //窗口监听事件
        this.addWindowListener(new WindowAdapter() {
            //当点击窗口的时候 出发的事件
            @Override
            public void windowClosing(WindowEvent e) {
                int dialog = JOptionPane.showConfirmDialog(null, "是否退出", "退出", JOptionPane.OK_CANCEL_OPTION);
                if(dialog == JOptionPane.OK_OPTION) {
                    System.exit(0);
                }
            }
        });


    }

}
